#ifndef WIDGETBOXTREEWIDGET_H
#define WIDGETBOXTREEWIDGET_H

#include "category.h"

#include <QTreeWidget>
#include <QXmlStreamReader>


class WidgetBoxCategoryListView;

class WidgetBoxTreeWidget: public QTreeWidget
{
    Q_OBJECT
public:
    explicit WidgetBoxTreeWidget(QWidget *parent = 0);
    ~WidgetBoxTreeWidget();

    int categoryCount() const;
    Category category(int cat_idx) const;

    int widgetCount(int cat_idx) const;
    Widget widget(int cat_idx, int wgt_idx) const;
    void addWidget(QString name, const Widget &wgt);


signals:
    void pressed(const QString name, const QString dom_xml, const QPoint &global_mouse_pos);
protected:
    void contextMenuEvent(QContextMenuEvent *e);
    void resizeEvent(QResizeEvent *e);

    void initWidgetBox();
private slots:
    void handleMousePress(QTreeWidgetItem *item);
    void handleMousePress(QString,QString,QPoint);
    void slotListMode();
    void slotIconMode();
private:

    WidgetBoxCategoryListView *addCategoryView(QTreeWidgetItem *parent, bool iconMode);
    WidgetBoxCategoryListView *categoryViewAt(int idx) const;
    void adjustSubListSize(QTreeWidgetItem *cat_item);

    int indexOfCategory(const QString &name) const;

    void updateViewMode();
    bool m_iconMode;
};

#endif // WIDGETBOXTREEWIDGET_H
